package work20240808.work8;

import work20240808.work7.lock;

import java.sql.SQLOutput;

public class sumTask {
    public static Object o = new Object();
    public static int sum = 0;
    public static int n = 1;
    public static void printTotal(){
        System.out.println("Total:" + sum);
    }
}
class A extends Thread {
    @Override
    public void run() {
        synchronized (lock.o) {
            while(sumTask.n != 1){
                try {
                    lock.o.wait();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
            for (int i = 1; i <= 10; i++) {
                System.out.print(i + " ");
                sumTask.sum += i;
            }

            System.out.println();
            sumTask.n++;
            lock.o.notifyAll();
        }
    }
}
class B extends Thread {
    @Override
    public void run() {
        synchronized (lock.o) {
            while(sumTask.n != 2){
                try {
                    lock.o.wait();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
            for (int i = 11; i <= 20; i++) {
                System.out.print(i + " ");
                sumTask.sum += i;
            }

            System.out.println();
            sumTask.n++;
            lock.o.notifyAll();
        }
    }
}
class C extends Thread {
    @Override
    public void run() {
        synchronized (lock.o) {
            while(sumTask.n != 3){
                try {
                    lock.o.wait();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
            for (int i = 21; i <= 30; i++) {
                System.out.print(i + " ");
                sumTask.sum += i;
            }
            System.out.println();
            sumTask.n++;
            lock.o.notifyAll();
        }
    }
}
class D extends Thread {
    @Override
    public void run() {
        synchronized (lock.o) {
            while(sumTask.n != 4){
                try {
                    lock.o.wait();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
            for (int i = 31; i <= 40; i++) {
                System.out.print(i + " ");
                sumTask.sum += i;
            }
            System.out.println();
            sumTask.n++;
            lock.o.notifyAll();
        }
    }
}
class E extends Thread {
    @Override
    public void run() {
        synchronized (lock.o) {
            while(sumTask.n != 5){
                try {
                    lock.o.wait();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
            for (int i = 41; i <= 50; i++) {
                System.out.print(i + " ");
                sumTask.sum += i;
            }
            System.out.println();
            sumTask.n++;
            lock.o.notifyAll();
        }
    }
}
class F extends Thread {
    @Override
    public void run() {
        synchronized (lock.o) {
            while(sumTask.n != 6){
                try {
                    lock.o.wait();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
            for (int i = 51; i <= 60; i++) {
                System.out.print(i + " ");
                sumTask.sum += i;
            }
            System.out.println();
            sumTask.n++;
            lock.o.notifyAll();
        }
    }
}
class G extends Thread {
    @Override
    public void run() {
        synchronized (lock.o) {
            while(sumTask.n != 7){
                try {
                    lock.o.wait();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
            for (int i = 61; i <= 70; i++) {
                System.out.print(i + " ");
                sumTask.sum += i;
            }
            System.out.println();
            sumTask.n++;
            lock.o.notifyAll();
        }
    }
}
class H extends Thread {
    @Override
    public void run() {
        synchronized (lock.o) {
            while(sumTask.n != 8){
                try {
                    lock.o.wait();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
            for (int i = 71; i <= 80; i++) {
                System.out.print(i + " ");
                sumTask.sum += i;
            }
            System.out.println();
            sumTask.n++;
            lock.o.notifyAll();
        }
    }
}
class I extends Thread {
    @Override
    public void run() {
        synchronized (lock.o) {
            while(sumTask.n != 9){
                try {
                    lock.o.wait();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
            for (int i = 81; i <= 90; i++) {
                System.out.print(i + " ");
                sumTask.sum += i;
            }
            System.out.println();
            sumTask.n++;
            lock.o.notifyAll();
        }
    }
}
class J extends Thread {
    @Override
    public void run() {
        synchronized (lock.o) {
            while(sumTask.n != 10){
                try {
                    lock.o.wait();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
            for (int i = 91; i <= 100; i++) {
                System.out.print(i + " ");
                sumTask.sum += i;
            }
            System.out.println();
            sumTask.n++;
            lock.o.notifyAll();
        }
    }
}
